home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
UTILITIE
/
CPU_MEMO
/
3468.ZIP
/
POPUP.ZIP
/
GETSTR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-06-30
|
5KB
|
142 lines
/*****************************************************************************
* Module : GETSTR.C *
*----------------------------------------------------------------------------*
* Program : POPUP LIBRARY *
*----------------------------------------------------------------------------*
* Author : M.R.Watson. Copyright (c) M.R.Watson 1988 *
*----------------------------------------------------------------------------*
* Last Updated : 24/06/88 *
*----------------------------------------------------------------------------*
* Synopsis *
* ======== *
* Auxilliary keyboard input functions to complement the screen functions *
* used in the popup library. These functions must only use BIOS routines. *
* DOS keyboard and screen routines are taboo in popup programs! *
* (But file handling DOS functions can be used.) *
*****************************************************************************/
#include <stdio.h>
#include <dos.h>
#include <standard.h>
#define BKSP 8
#define RET 13
#define ESC 27
/*****************************************************************************
* int GetString( int y, int x, char *buffer, int length, int attr ) *
*----------------------------------------------------------------------------*
* Gets a string from the user at the given location, using BIOS only. *
* If the ESC key is pressed, ESC is returned, else RET is returned *
*****************************************************************************/
GetString( int y, int x, char *buffer, int length, int attr )
{
int i, c ;
int sx, sy ;
ClearBox( y, x, y, x+length-1, attr );
GetCursor(&sy,&sx);
i = 0 ;
FOREVER
{
SetCursor(y,x+i);
c = getkey();
if (c == ESC) /* Escape key pressed */
{
SetCursor(sy,sx);
return(ESC);
}
else if (c == RET) /* Return key pressed */
{
SetCursor(sy,sx);
buffer[i] = EOS ; /* Terminate string entered */
return(RET);
}
else if (c == BKSP) /* Backspace key pressed */
{
if (--i < 0)
i = 0 ;
CharAt( y, x+i, ' ', attr ); /* Erase last character */
buffer[i] = EOS ; /* Shorten buffer string */
}
else if (c < 256) /* Character to go in buffer */
{
if ( i < length ) /* If there's room left */
{
buffer[i] = c ;
CharAt( y, x+i, c, attr );
i++ ;
}
else
bell();
}
}
}
/*****************************************************************************
* SetCursor( int y, int x ) *
*----------------------------------------------------------------------------*
* Sets the cursor position to row = y, column = x. *
*****************************************************************************/
SetCursor( int y, int x )
{
union REGS r ;
r.h.ah = 2 ;
r.h.dh = y ;
r.h.dl = x ;
r.h.bh = 0 ;
int86( 0x10, &r, &r );
}
/*****************************************************************************
* GetCursor( int *y, int *x ) *
*----------------------------------------------------------------------------*
* Gets the cursor position into row = y, column = x. *
*****************************************************************************/
GetCursor( int *y, int *x )
{
union REGS r ;
r.h.ah = 3 ;
r.h.bh = 0 ;
int86( 0x10, &r, &r );
*x = r.h.dl ;
*y = r.h.dh ;
}
/*****************************************************************************
* void bell(void) : Bleep using the BIOS. *
*****************************************************************************/
bell()
{
union REGS r ;
r.x.ax = 0x0E07 ;
int86( 0x10, &r, &r );
}
/*****************************************************************************
* void CharAt( int y, int x, int c, int attr ) *
*----------------------------------------------------------------------------*
* Displays the character 'c' at row 'y', column 'x', using attribute 'attr'. *
*****************************************************************************/
CharAt( int y, int x, int c, int attr )
{
c |= (attr << 8);
WriteScreen( y, x, &c, 1 );
}